import React,{Component} from 'react'
import login from './Login.module.css'
import { Input } from 'antd';
import { Button } from 'antd';
import {NavLink} from 'react-router-dom'
import*as api from '../until/login.js'
export default class Login extends Component{
	log(){
		api.login({
			userName: document.querySelector('#ipt').value,
			password: document.querySelector('#ipt1').value
		}).then((res) => {
			console.log(res.data)
			if(res.data.code==='success'){
				localStorage.setItem('token',res.data.token)
				this.props.history.push('/index')
			}else{
				alert(res.data.message)
				document.querySelector('#ipt1').value=''
			}
		})
	}
	render(){
		return(
			<div className={login.body}>
				<div className={login.box}>
					<p>欢迎回来,请登录</p>
					<Input placeholder="请输入账号"  id='ipt'/>
					<Input placeholder="请输入密码" type="password" id='ipt1'/>
					<Button type="danger" onClick={()=>this.log()} className={login.button}>登录</Button>
					<NavLink to='/register' className={login.span}>我要注册</NavLink>
				</div>
			</div>
		)
	}
}